# MIT License
#
# Copyright (c) 2025 milkpotatoes
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

cmake_minimum_required(VERSION 3.10)

set(CMAKE_CXX_STANDARD 17)
project(ArkuiNapiSdk)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

execute_process(
    COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/../tools/gen_sdk_source.py"
    --api-list ${CMAKE_CURRENT_SOURCE_DIR}/napi.ndk.list
    --output "${CMAKE_CURRENT_BINARY_DIR}/napi.sdk.c"
    OUTPUT_VARIABLE arkui_napi_sdk_srcs
    OUTPUT_STRIP_TRAILING_WHITESPACE
)

execute_process(
    COMMAND cp -r "${CMAKE_CURRENT_SOURCE_DIR}/../arkui_napi/interfaces/kits" "${CMAKE_CURRENT_SOURCE_DIR}/include"
    OUTPUT_VARIABLE copy_result
    OUTPUT_STRIP_TRAILING_WHITESPACE
)

add_library(ace_napi_sdk SHARED ${arkui_napi_sdk_srcs})
if(CMAKE_SYSTEM_NAME STREQUAL "OHOS")
    set_target_properties(ace_napi_sdk PROPERTIES
        OUTPUT_NAME "ace_napi"
        PREFIX "lib"
        SUFFIX ".z.so"
    )
else()
    set_target_properties(ace_napi_sdk PROPERTIES
        OUTPUT_NAME "ace_napi"
        PREFIX "lib"
        SUFFIX ".so"
    )
endif()

target_include_directories(ace_napi_sdk BEFORE PUBLIC include ${ARK_ABS_REPO_PATH}/third_party/node/src)
export(TARGETS ace_napi_sdk NAMESPACE ArkuiNapi:: FILE ${CMAKE_CURRENT_SOURCE_DIR}/arkui_napi.sdk.cmake)
